let ipt1 = document.querySelector('#ipt1')
let ipt2 = document.querySelector('#ipt2')
let btn = document.querySelector('#btn')
let ems = document.querySelectorAll('em')

// 正则判断账号格式
ipt1.onblur = function() {
    let g = ipt1.value;
    let i = /([a-zA-Z]|[\u2e80-\u9FFF]|[0-9]){1,8}$/;
    if (i.test(g) == false) {
        ems[0].innerHTML = '账号格式错误'
    } else {
        ems[0].innerHTML = ''
    }
}

// 判断用户名是否可用
ipt1.onchange = function() {
    let username = ipt1.value
    axios.get(isregAPI, {
        params: {
            username
        }
    }).then(res => {
        console.log(res);
    })
}

// 正则判断密码格式
ipt2.onblur = function() {
    let g = ipt2.value;
    let i = /^[a-zA-Z0-9_-]{6,16}$/;
    if (i.test(g) == false) {
        ems[1].innerHTML = '密码格式错误'
    } else {
        ems[1].innerHTML = ''
    }
}

btn.onclick = function() {
    let username = ipt1.value
    let password = ipt2.value
    let params = {
        username,
        password,
    };
    axios.get(regAPI, {
        params
    }).then(res => {
        console.log(res);
        alert(res.data.msg);
        if (res.data.code == 1) {
            location.href = "logoin.html";
        }
    })
}